/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sle_bridge_proxy.h"
#include "ipc_skeleton.h"
#include "system_ability_definition.h"
#include "iservice_registry.h"
#include "sle_bridge_client.h"
#include "iot_connect_log.h"
#include "sle_bridge_ipcomm.h"

using namespace std;
using namespace OHOS;
using namespace OHOS::iotConnect;
namespace OHOS{

namespace iotConnect {
IMPLEMENT_SINGLE_INSTANCE(SleBridgeClient);

sptr<ISleBridge> getRemoteProxy()
{
    auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
    if (saMgr == nullptr) {
        return nullptr;
    }
    sptr<IRemoteObject> object = saMgr->GetSystemAbility(IOT_CONNECT_SLE_BRIDGE_COMM_ID);
    sptr<ISleBridge> proxy = nullptr;
    if (object != nullptr) {
        sptr<IRemoteObject::DeathRecipient> death(new SleBridgeDeathRecipient());
        object->AddDeathRecipient(death.GetRefPtr());
        proxy = iface_cast<ISleBridge>(object);
    }
    if (proxy == nullptr) {
        HILOGE("proxy == nullptr");
        return nullptr;
    }
    return proxy;
}

}
}
